<!--
 * @Author: your name
 * @Date: 2021-06-11 15:15:27
 * @LastEditTime: 2021-07-14 09:57:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \dolphin-data-center-front-end\src\pages\socialSecurityFund\detailTabs\tab2.vue
-->
<template>
  <div class="serveLog_div">
    <a-table :columns="serviceLogColumns" :data-source="serviceLogData" :pagination="false" rowKey="id">
      <a slot="workId" slot-scope="text, record" @click="todoClkFn(record)">{{ text }}</a>
      <template slot="updateTime" slot-scope="text">{{text | transferDateFilter}}</template>
    </a-table>

    <!-- 详情drawer -->
    <a-drawer :title="detailTitle+'详情'" width="1080px" placement="right" :visible="drawerDetail" destroy-on-close @close="onClose">
      <orderDetail :id="rowId" :taskType="taskTypeCpt" :taskErrorType="taskErrorTypeObj"></orderDetail>
    </a-drawer>
  </div>
</template>
  
<script>
import datas from '@/utils/data'
import { queryDetailApi, proNameBaseSelectApi } from '@/services/socialSecurityFund'
import orderDetail from '@/pages/todoOrder/orderDetail'
import { transferDate } from '@/utils/util'

export default {
  name: '',
  components: { orderDetail },
  data () {
    return {
      serviceLogColumns: datas.serviceLogColumns,
      serviceLogData: [],
      detailTitle: '',
      drawerDetail: false,
      rowId: null,
      taskErrorTypeObj: {}
    }
  },
  computed: {
    taskTypeCpt () {
      // add_cut 增减员 增减员详情
      // adjusted_basis 调基 调基详情
      // make_up 补缴  补缴详情
      // error 异常  社保公积金异常详情
      let $type
      this.serviceLogData.forEach(item => {
        if (item.typeName == "公积金增员" || item.typeName == '社保增员' || item.typeName == '公积金减员' || item.typeName == '社保减员') {
          this.detailTitle = '增减员'
          $type = 'add_cut'
        } else if (item.typeName == "社保调基" || item.typeName == "公积金调基") {
          this.detailTitle = '调基'
          $type = 'adjusted_basis'
        } else if (item.typeName == "社保补缴" || item.typeName == "公积金补缴") {
          this.detailTitle = '补缴'
          $type = 'make_up'
        } else if (item.typeName == "社保补缴异常" || item.typeName == "公积金补缴异常" || item.typeName == "公积金增员异常" || item.typeName == "公积金减员异常" || item.typeName == "社保增员异常" || item.typeName == "社保减员异常" || item.typeName == '公积金调基异常' || item.typeName == '社保调基异常') {
          this.detailTitle = '社保公积金异常'
          $type = 'error'
        }
      })
      return $type
    }
  },
  created () {
    if (this.$Storage.get('serveLogVal')) {
      this.getData(this.$Storage.get('serveLogVal'))
    }
    this.getBaseSelectIvk()
  },
  filters: {
    transferDateFilter (i) {
      return i ? transferDate(i, 0) : '-'
    }
  },
  methods: {
    getData (empId) {
      queryDetailApi({ empId }).then(res => {
        let { code, msg, data } = res.data
        if (code === 200) {
          this.serviceLogData = data
        } else {
          this.$message.error(msg)
        }
      })
    },
    todoClkFn (data) {
      this.drawerDetail = true
      this.rowId = data.id
    },

    getBaseSelectIvk () {
      proNameBaseSelectApi().then(res => {
        let { code, data, msg } = res.data
        if (code === 200) {
          this.taskErrorTypeObj = data.taskErrorType
        } else {
          this.$message.error(msg)
        }
      })
    },

    onClose () {
      this.drawerDetail = false
    },
  }
}
</script>
  
<style scoped lang='less'>
</style>